<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公司历史</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
<div class="Wrapper">
        <form id="cust_company_history_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">项目名称</div>
                    <div class="field">
                        <input name="prjNm" id="prjNm" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:30}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
               <div class="fieldBox col_50">
			       <div class="label">开始日期</div>
			           <div class="field">
			              <input name="startDt" id="startDt" readonly="readonly" type="text" class="ui-datepicker" value="" validate="{required:true}">
			              <span class="requiredSymbol">*</span>
			           </div>
			   </div>
               <div class="fieldBox col_50">
			       <div class="label">结束日期</div>
			           <div class="field">
			              <input name="endDt" id="endDt" type="text" class="ui-datepicker" value="" validate="{required:true}">
			              <span class="requiredSymbol">*</span>
			           </div>
			   </div>
                
                <div class="fieldBox col_100">
                    <div class="label">描述</div>
                    <div class="field" style="width: 100%;">
                        <textarea name="prjDesc" id="prjDesc" rows="4" class="l-textarea" style="width:92%" validate="{maxlength:250}" placeholder=""></textarea>
                    </div>
                </div>
                
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
		              <input name="chid" id="chid" type="text" class="ui-textbox" value="${id}">
		          </div>
		        </div>
            </div>
        </form>
      </div>
	<script>
	
	$(function() {
		initForm();
	   	initEvent();
	    initData();
	});
		
		//初始化表单
		function initForm(){
			$("#cust_company_history_form").ligerForm({
                validate: true
           });
		}
		
		//初始化事件
		function initEvent(){
			
		}
		
		
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("cust_company_history_form");
            if (!ligerForm.valid()) {
            	UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            
            var _id = $("#chid").val();
            var url = '<%=path%>/customer/cstcorphis/add.do';
            if(_id != ""){
            	url = '<%=path%>/customer/cstcorphis/modify.do';
            	data["id"]= _id;
            }
            //设置客户ID
            var cstId = $("#cstId").val();
            data["cstId"]= cstId;
            AjaxUtils.ajaxPost(url, data, saveCallback, true);
		}
		
		//回调
		function saveCallback(msg){
			 if(msg.success == 1){
				 var cstId = $("#cstId").val();
				 UIUtils.alertSuccess(msg.info);
				 parent.companyHistoryGrid.setParm("cstId",cstId);
				 parent.companyHistoryGrid.reload();
				 frameElement.dialog.close();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}

		
		//初始化数据
		function initData(){
			var chid = $("#chid").val();
	    	if(!chid)return;
	    	var _url = '<%=path%>/customer/cstcorphis/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:chid}, initCallback, true);
    	}
		
		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_company_history_form");
	    	form.setData({
	    		prjNm:data.prjNm,
	    		startDt:data.startDt,
	    		endDt:data.endDt,
	    		prjDesc:data.prjDesc
	    	});
		};
	</script>
</body>
</html>